package com.woniuxy.gateway.filter;


import com.woniuxy.entity.ResponseResult;
import com.woniuxy.gateway.service.SecurityService;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.util.MultiValueMap;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import javax.annotation.Resource;

//@Component
public class UserLoginFilter implements GlobalFilter, Ordered {
    @Resource
    private SecurityService securityService;

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        String uri = exchange.getRequest().getURI().toString();
        if(uri.contains("login")){
            Mono<MultiValueMap<String, String>> data = exchange.getFormData();
            String account = null;
            String password = exchange.getAttribute("password");
            ResponseResult<?> responseResult = securityService.login(account,password);
            System.out.println(responseResult);
            return null;
        }else{
            return chain.filter(exchange);
        }
    }

    @Override
    public int getOrder() {
        return -100;
    }
}
